package com.hzqy.web.ac.epg;


import com.hzqy.commons.utils.ExcelUtil;
import com.hzqy.commons.utils.ExcelUtil.MyEntry;
import com.hzqy.service.epg.AcRecordService;
import com.hzqy.web.vo.AcWinningVo;
import com.hzqy.web.vo.epg.AcRecordVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/acRecord")
public class AcRecordAction {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
    @Resource
	private AcRecordService serviceAction;
    @RequestMapping("/acRecordSelectAll")
	@ResponseBody
	public Object acRecordSelect(AcRecordVo arv, int page, int rows){
		Map<String,Object> RecordListMap = new HashMap<String, Object>();
		if(!"".equals(arv.getType()) && !"0".equals(arv.getType())) {
			RecordListMap = serviceAction.selectServerList(arv, page, rows);
		}else {
			RecordListMap= serviceAction.selectAc(arv,page, rows);
		}
		return RecordListMap;
	}
	@RequestMapping("/acRecordExcel")
	@ResponseBody
	public void acRecordExcel(AcRecordVo infoVo, HttpSession session, int page, int rows, HttpServletResponse response) throws IOException {
		Map<String,Object> ListMap = new HashMap<String, Object>();
    	
		if(!"".equals(infoVo.getType()) && !"0".equals(infoVo.getType())) {
			ListMap = serviceAction.selectServerList(infoVo, 1,100000);
		}else {
			ListMap= serviceAction.selectAc(infoVo,1,100000);
		}
		//ListMap = serviceAction.selectAc(infoVo,(page-1)*rows,rows);
		List<AcWinningVo> data=(List<AcWinningVo>)ListMap.get("rows");
		List<MyEntry<String, String>> excelHeader=new ArrayList<MyEntry<String, String>>();
		excelHeader.add(new MyEntry<String,String>("f_ar_id","ID"));
		excelHeader.add(new MyEntry<String,String>("f_ar_serverid","业务帐号"));
		excelHeader.add(new MyEntry<String,String>("f_ar_name","活动名称"));
		excelHeader.add(new MyEntry<String,String>("f_ar_activityid","活动编号"));
		excelHeader.add(new MyEntry<String,String>("rownum","榜单排名(榜单专用)"));
		excelHeader.add(new MyEntry<String,String>("count","总积分(榜单专用)"));
		excelHeader.add(new MyEntry<String,String>("f_ar_periods","戏曲答题成绩：查询榜单时此列无效"));
		excelHeader.add(new MyEntry<String,String>("f_ar_phone","手机号码(戏曲答题：0)"));
		excelHeader.add(new MyEntry<String,String>("f_ar_target","竞猜目标(戏曲答题为null)"));
		excelHeader.add(new MyEntry<String,String>("f_ar_type","类型（3戏曲答题，1中奖，2未中奖）"));
		excelHeader.add(new MyEntry<String,String>("f_ar_udate","更新时间"));
		excelHeader.add(new MyEntry<String,String>("f_ar_cdate","创建时间"));
		boolean flag= ExcelUtil.generateExcel(data, excelHeader, response);
	}
	/**戏曲答题使用
	 * f_ar_serverid ;//业务帐号
	 * f_ar_activityid ;//活动编号
	 * f_ar_name ;//活动名称
	 * f_ar_phone;//默认设为0
	 * f_ar_type;//默认设为3
	 * f_ar_target;//默认设为null
	 * f_ar_periods;//记录每次答题成绩
	 * rownum;//排名
	 * count;//总积分
	 * type;//查询类型 1:按月统计，2:按季统计
	 */
	
	@RequestMapping("/insertRecord")
	@ResponseBody
	public Object insertRecordAction(AcRecordVo arv){
		Map<String,Object> RecordListMap = new HashMap<String, Object>();
		RecordListMap = serviceAction.insertRecord(arv);
		return RecordListMap;
	}
	
	@RequestMapping("/updateRecord")
	@ResponseBody
	public Object updateRecordAction(AcRecordVo arv){
		Map<String,Object> RecordListMap = new HashMap<String, Object>();
		RecordListMap = serviceAction.updateRecord(arv);
		return RecordListMap;
	}
	
	@RequestMapping("/deleteRecord")
	@ResponseBody
	public Object deleteRecordAction(int f_ar_id){
		Map<String,Object> RecordListMap = new HashMap<String, Object>();
		RecordListMap = serviceAction.deleteRecord(f_ar_id);
		return RecordListMap;
	}
	
	@RequestMapping("/selectRecordById")
	@ResponseBody
	public Object selectRecordByIdAction(int f_ar_id){
		return serviceAction.selectRecordById(f_ar_id);
	}

}
